package com.jiyun.behavior.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.behavior.mapper.ApBehaviorEntryMapper;
import com.jiyun.behavior.mapper.ApFollowBehaviorMapper;
import com.jiyun.behavior.mapper.ApLikesBehaviorMapper;
import com.jiyun.behavior.mapper.ApUnlikesBehaviorMapper;
import com.usian.model.atri.pojos.dto.ArticleInfoDto;
import com.usian.model.behavior.ApBehaviorEntry;
import com.usian.model.behavior.ApFollowBehavior;
import com.usian.model.behavior.ApLikesBehavior;
import com.usian.model.behavior.ApUnlikesBehavior;
import com.usian.model.user.pojos.ApUser;
import com.usian.utils.threadlocal.AppThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/behavior/api/v1/behavior")
@RestController
public class WenzhangDuoBiaoController {
    @Resource
    ApBehaviorEntryMapper apBehaviorEntryMapper;

    @Resource
    ApFollowBehaviorMapper apFollowBehaviorMapper;

    @Resource
    ApLikesBehaviorMapper apLikesBehaviorMapper;

    @Resource
    ApUnlikesBehaviorMapper apUnlikesBehaviorMapper;


    @PostMapping("apBehaviorEntry")
    public ApBehaviorEntry apBehaviorEntry(@RequestBody ArticleInfoDto dto){
        ApUser user = AppThreadLocalUtils.getUser();
        LambdaQueryWrapper<ApBehaviorEntry> qw=new LambdaQueryWrapper<>();
        qw.eq(ApBehaviorEntry::getId,user.getId());
        return  apBehaviorEntryMapper.selectOne(qw);
    }

    @PostMapping("apUnlikesBehavior")
    public  ApUnlikesBehavior apUnlikesBehavior(@RequestBody ArticleInfoDto dto){
        LambdaQueryWrapper<ApUnlikesBehavior> qw=new LambdaQueryWrapper<>();
        qw.eq(ApUnlikesBehavior::getArticleId,dto.getArticleId());
        return  apUnlikesBehaviorMapper.selectOne(qw);
    }

    @PostMapping("apLikesBehavior")
    public  ApLikesBehavior apLikesBehavior(@RequestBody ArticleInfoDto dto){
        LambdaQueryWrapper<ApLikesBehavior> qw=new LambdaQueryWrapper<>();
        qw.eq(ApLikesBehavior::getArticleId,dto.getArticleId());
        return  apLikesBehaviorMapper.selectOne(qw);
    }

    @PostMapping("apFollowBehavior")
    public ApFollowBehavior apFollowBehavior(@RequestBody ArticleInfoDto dto){
        LambdaQueryWrapper<ApFollowBehavior> qw=new LambdaQueryWrapper<>();
        qw.eq(ApFollowBehavior::getArticleId,dto.getArticleId());
        return  apFollowBehaviorMapper.selectOne(qw);
    }

}
